/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.GUI;

import edu.nii.qlks.ControlLayer.PhieuDenControl;
import edu.nii.qlks.ControlLayer.PhongControl;
import edu.nii.qlks.DataTransferObject.PhieuDenInfo;
import edu.nii.qlks.DataTransferObject.PhongInfo;
import java.awt.Color;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.HighlightPredicate;

/**
 *
 * @author KUUT
 */
public class JInternal_Timkiem extends javax.swing.JInternalFrame {

    
    PhongControl phong_control;
    PhongInfo phong_info;
    
    PhieuDenControl phieuthuephong_control;
    PhieuDenInfo phieuthuphong_info;
    
    Vector table_record;
    Vector table_title;
    
    SimpleDateFormat sdf = new SimpleDateFormat () ;
    
    static String ngaythue_tungay = "";
    static String ngaythue_denngay = "";
    static String ngaytra_tungay = "";
    static String ngaytra_denngay = "";
    
    static int dieukien_timkiem = 1;
    static int dk_phong = 1;
    static int dk_ngaythue = 2;
    static int dk_ngaytra = 3;
    static Date datemin;
    static Date datemax;
    
    public JInternal_Timkiem() throws Exception {
        initComponents();
        float[] color = new float[3];
        color = Color.RGBtoHSB(255,255,255,color);
        this.getContentPane().setBackground(Color.getHSBColor(color[0], color[1], color[2]));
        phong_control = new PhongControl();
        phong_info = new PhongInfo();
        phieuthuephong_control = new PhieuDenControl();
        phieuthuphong_info = new PhieuDenInfo();
        
        table_record = new Vector();
        table_title = new Vector();
                  
        table_title.add("STT");
        table_title.add("Tên phòng");
        table_title.add("Tên loại phòng");
        table_title.add("Tình trạng");
        table_title.add("Ghi chú");
        
        jComboBox_Tenphong.setModel(new DefaultComboBoxModel(phong_control.LayTenPhong()));
        jComboBox_Tenphong.insertItemAt("", 0);
        jComboBox_Tenphong.setSelectedIndex(0);
        
        jComboBox_Tenloaiphong.setModel(new DefaultComboBoxModel(phong_control.LayTenLoaiPhong()));
        jComboBox_Tenloaiphong.insertItemAt("", 0);
        jComboBox_Tenloaiphong.setSelectedIndex(0);
        
        
        Object[] tinhtrang = {"" ,"true", "false"};
        jComboBox_Tinhtrang.setModel(new DefaultComboBoxModel(tinhtrang));
        jComboBox_Tinhtrang.setSelectedIndex(0);
        
        //Tự động hiện từ khi bấm chữ trên Combobox
        AutoCompleteDecorator.decorate(this.jComboBox_Tenphong);
        AutoCompleteDecorator.decorate(this.jComboBox_Tenloaiphong);
        AutoCompleteDecorator.decorate(this.jComboBox_Tinhtrang);
       
        LayDS_TimKiem();
        KeyPress();
        
        jXDatePicker_NgayThue_Tungay.setFormats(new SimpleDateFormat("dd/MM/yyyy")); 
        jXDatePicker_Ngaythue_Denngay.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        jXDatePicker_Ngaytra_Tungay.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        jXDatePicker_Ngaytra_Denngay.setFormats(new SimpleDateFormat("dd/MM/yyyy"));
        
        sdf.applyPattern("MM/dd/yyyy") ;
        sdf.setLenient(false) ;
        datemin = sdf.parse("1/1/1990");
        datemax = sdf.parse("1/1/2100");
        
        jXTable_Danhsachphong.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW,
        null, Color.RED));
    }
    
    public void KeyPress(){
        //Enter Combobox Tên phòng
        jComboBox_Tenphong.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() 
        {
            @Override
            public void keyPressed(KeyEvent evt)
            {
                if(evt.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    try{
                        TimKiemPhong();
                        clear();
                    }catch(Exception e){
                        JOptionPane.showMessageDialog(null, "Không tim thấy"
                                , "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                }
            }
        });
        
        //Enter Combobox Tên loại phòng
        jComboBox_Tenloaiphong.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() 
        {
            @Override
            public void keyPressed(KeyEvent evt)
            {
                if(evt.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    try{
                        TimKiemPhong();
                        clear();
                    }catch(Exception e){
                        JOptionPane.showMessageDialog(null, "Không tim thấy"
                                , "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                }
            }
        });
        
        //Enter Combobox Tình trạng
        jComboBox_Tinhtrang.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() 
        {
            @Override
            public void keyPressed(KeyEvent evt)
            {
                if(evt.getKeyCode() == KeyEvent.VK_ENTER)
                {
                    try{
                        TimKiemPhong();
                        clear();
                    }catch(Exception e){
                        JOptionPane.showMessageDialog(null, "Không tim thấy"
                                , "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                }
            }
        });
    }
    
    public void LayDS_TimKiem() throws Exception{
        table_record = phong_control.LayDS_TimKiem();
        jXTable_Danhsachphong.setModel(new DefaultTableModel(table_record, table_title));
    }
    
    public void clear(){
        jComboBox_Tenloaiphong.setSelectedIndex(0);
        jComboBox_Tenphong.setSelectedIndex(0);
        jComboBox_Tinhtrang.setSelectedIndex(0);
    }
    
    public void TimKiemNgayThue() throws Exception{
        table_record = phieuthuephong_control.TimKiemNgayThue(ngaythue_tungay, ngaythue_denngay);
        jXTable_Danhsachphong.setModel(new DefaultTableModel(table_record, table_title));
    }
    
    public void TimKiemNgayTra() throws Exception{
        table_record = phieuthuephong_control.TimKiemNgayTra(ngaytra_tungay, ngaytra_denngay);
        jXTable_Danhsachphong.setModel(new DefaultTableModel(table_record, table_title));
    }
    
    public void NgayHopLe(String ngay){
        SimpleDateFormat datefor = new SimpleDateFormat();
        datefor.setLenient(false);
        datefor.applyPattern("dd/MM/yyyy");
        Date date;
        
        try{
            date = datefor.parse(ngay.trim());
            String a = datefor.format(date);
            if(date.compareTo(datemin) < 0){
                JOptionPane.showMessageDialog(null, "Ngày nhỏ nhất trong quy định là 1/1/1990"
                            , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            if(date.compareTo(datemax) > 0){
                JOptionPane.showMessageDialog(null, "Ngày lớn nhất trong quy định là 1/1/2100"
                            , "Warning", JOptionPane.WARNING_MESSAGE);
            }
            
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Định dạng ngày dd/MM/yyyy"
                            , "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }
    
    public void TimKiemPhong() throws Exception{
        
        String tenloaiphong;
        String tinhtrang = "";
        
        if(jComboBox_Tenphong.getSelectedIndex() < 0 ){
            //Lấy Giá trị từ combobox khi gõ từ
            String tenphong = (String)jComboBox_Tenphong.getEditor().getItem().toString();
            phong_info.setTenPhong(tenphong);
        }else if(jComboBox_Tenphong.getSelectedIndex() == 0){
            phong_info.setTenPhong("");
        }
        else{
            phong_info.setTenPhong(jComboBox_Tenphong.getSelectedItem().toString().trim());
        }
        //Lay gia tri từ Combobox khi gõ từ
        if(jComboBox_Tenloaiphong.getSelectedIndex() < 0){
            String comboboxText = (String)jComboBox_Tenloaiphong.getEditor().getItem().toString();
            tenloaiphong = comboboxText;
            
        }
        else{
            tenloaiphong = jComboBox_Tenloaiphong.getSelectedItem().toString().trim();
        }
        
        if(jComboBox_Tinhtrang.getSelectedIndex() < 0){
            tinhtrang = "";
        }
        else{
            if(jComboBox_Tinhtrang.getSelectedIndex() == 1){
                tinhtrang = "true";
            }else if(jComboBox_Tinhtrang.getSelectedIndex() == 2){
                tinhtrang = "false";
            }
        }
        
        table_record = phong_control.TimKiemPhong(phong_info, tenloaiphong, tinhtrang);
        jXTable_Danhsachphong.setModel(new DefaultTableModel(table_record, table_title));
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane_TTTimkiem = new javax.swing.JTabbedPane();
        jXPanel2 = new org.jdesktop.swingx.JXPanel();
        jXLabel2 = new org.jdesktop.swingx.JXLabel();
        jXLabel3 = new org.jdesktop.swingx.JXLabel();
        jXLabel_Tinhtrang = new org.jdesktop.swingx.JXLabel();
        jComboBox_Tenphong = new javax.swing.JComboBox();
        jComboBox_Tenloaiphong = new javax.swing.JComboBox();
        jComboBox_Tinhtrang = new javax.swing.JComboBox();
        jXPanel3 = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jXLabel6 = new org.jdesktop.swingx.JXLabel();
        jXDatePicker_NgayThue_Tungay = new org.jdesktop.swingx.JXDatePicker();
        jXDatePicker_Ngaythue_Denngay = new org.jdesktop.swingx.JXDatePicker();
        jXLabel4 = new org.jdesktop.swingx.JXLabel();
        jXLabel9 = new org.jdesktop.swingx.JXLabel();
        jXPanel6 = new org.jdesktop.swingx.JXPanel();
        jXDatePicker_Ngaytra_Tungay = new org.jdesktop.swingx.JXDatePicker();
        jXLabel7 = new org.jdesktop.swingx.JXLabel();
        jXLabel8 = new org.jdesktop.swingx.JXLabel();
        jXDatePicker_Ngaytra_Denngay = new org.jdesktop.swingx.JXDatePicker();
        jXPanel1 = new org.jdesktop.swingx.JXPanel();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jXPanel5 = new org.jdesktop.swingx.JXPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTable_Danhsachphong = new org.jdesktop.swingx.JXTable();
        jXButton_Timkiem = new org.jdesktop.swingx.JXButton();
        jXButton_Thoat = new org.jdesktop.swingx.JXButton();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));

        jTabbedPane_TTTimkiem.setBackground(new java.awt.Color(204, 255, 255));
        jTabbedPane_TTTimkiem.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Thông tin tìm kiếm", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 18), new java.awt.Color(255, 0, 0))); // NOI18N
        jTabbedPane_TTTimkiem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane_TTTimkiemMouseClicked(evt);
            }
        });

        jXPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jXLabel2.setText("Tên phòng");

        jXLabel3.setText("Tên loại phòng");

        jXLabel_Tinhtrang.setText("Tình trạng");

        jComboBox_Tenphong.setBackground(new java.awt.Color(255, 249, 156));
        jComboBox_Tenphong.setEditable(true);
        jComboBox_Tenphong.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jComboBox_Tenloaiphong.setBackground(new java.awt.Color(255, 249, 156));
        jComboBox_Tenloaiphong.setEditable(true);
        jComboBox_Tenloaiphong.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jComboBox_Tinhtrang.setBackground(new java.awt.Color(255, 249, 156));
        jComboBox_Tinhtrang.setEditable(true);
        jComboBox_Tinhtrang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout jXPanel2Layout = new javax.swing.GroupLayout(jXPanel2);
        jXPanel2.setLayout(jXPanel2Layout);
        jXPanel2Layout.setHorizontalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jComboBox_Tenphong, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53)
                .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jComboBox_Tenloaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 95, Short.MAX_VALUE)
                .addComponent(jXLabel_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(jComboBox_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(24, 24, 24))
        );
        jXPanel2Layout.setVerticalGroup(
            jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel2Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jXPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_Tenphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_Tenloaiphong, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox_Tinhtrang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane_TTTimkiem.addTab("Thông tin về phòng", jXPanel2);

        jXPanel3.setBackground(new java.awt.Color(255, 255, 255));

        jXLabel5.setText("Từ Ngày");

        jXLabel6.setText("Đến Ngày");

        jXDatePicker_NgayThue_Tungay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXDatePicker_NgayThue_TungayActionPerformed(evt);
            }
        });

        jXDatePicker_Ngaythue_Denngay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXDatePicker_Ngaythue_DenngayActionPerformed(evt);
            }
        });

        jXLabel4.setText("dd/MM/yyyy");

        jXLabel9.setText("dd/MM/yyyy");

        javax.swing.GroupLayout jXPanel3Layout = new javax.swing.GroupLayout(jXPanel3);
        jXPanel3.setLayout(jXPanel3Layout);
        jXPanel3Layout.setHorizontalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel3Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXDatePicker_NgayThue_Tungay, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 142, Short.MAX_VALUE)
                .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(jXDatePicker_Ngaythue_Denngay, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(88, 88, 88))
        );
        jXPanel3Layout.setVerticalGroup(
            jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel3Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jXPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXDatePicker_NgayThue_Tungay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXDatePicker_Ngaythue_Denngay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane_TTTimkiem.addTab("Ngày thuê", jXPanel3);

        jXPanel6.setBackground(new java.awt.Color(255, 255, 255));

        jXDatePicker_Ngaytra_Tungay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXDatePicker_Ngaytra_TungayActionPerformed(evt);
            }
        });

        jXLabel7.setText("Từ Ngày");

        jXLabel8.setText("Đến Ngày");

        jXDatePicker_Ngaytra_Denngay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXDatePicker_Ngaytra_DenngayActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jXPanel6Layout = new javax.swing.GroupLayout(jXPanel6);
        jXPanel6.setLayout(jXPanel6Layout);
        jXPanel6Layout.setHorizontalGroup(
            jXPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel6Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXDatePicker_Ngaytra_Tungay, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(68, 68, 68)
                .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(jXDatePicker_Ngaytra_Denngay, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(290, Short.MAX_VALUE))
        );
        jXPanel6Layout.setVerticalGroup(
            jXPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel6Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jXPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXDatePicker_Ngaytra_Tungay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXDatePicker_Ngaytra_Denngay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        jTabbedPane_TTTimkiem.addTab("Ngày trả", jXPanel6);

        jXPanel1.setBackground(new java.awt.Color(0, 51, 204));

        jXLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jXLabel1.setText("TÌM KIẾM");
        jXLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N

        javax.swing.GroupLayout jXPanel1Layout = new javax.swing.GroupLayout(jXPanel1);
        jXPanel1.setLayout(jXPanel1Layout);
        jXPanel1Layout.setHorizontalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(389, 389, 389))
        );
        jXPanel1Layout.setVerticalGroup(
            jXPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                .addContainerGap())
        );

        jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
        jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Danh sách phòng", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 18), new java.awt.Color(255, 0, 0))); // NOI18N

        jXTable_Danhsachphong.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "STT", "Tên phòng", "Tên loại phòng", "Tình trạng",
                "Ghi chú"
            }
        ));
        jXTable_Danhsachphong.setEditable(false);
        jScrollPane1.setViewportView(jXTable_Danhsachphong);

        javax.swing.GroupLayout jXPanel5Layout = new javax.swing.GroupLayout(jXPanel5);
        jXPanel5.setLayout(jXPanel5Layout);
        jXPanel5Layout.setHorizontalGroup(
            jXPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jXPanel5Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1022, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jXPanel5Layout.setVerticalGroup(
            jXPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jXPanel5Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jXButton_Timkiem.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Timkiem.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Timkiem.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/search.png"))); // NOI18N
        jXButton_Timkiem.setText("TÌM KIẾM");
        jXButton_Timkiem.setBorderPainted(false);
        jXButton_Timkiem.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jXButton_Timkiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_TimkiemActionPerformed(evt);
            }
        });

        jXButton_Thoat.setBackground(new java.awt.Color(0, 51, 204));
        jXButton_Thoat.setForeground(new java.awt.Color(255, 255, 255));
        jXButton_Thoat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/icon/exit.png"))); // NOI18N
        jXButton_Thoat.setText("THOÁT");
        jXButton_Thoat.setBorderPainted(false);
        jXButton_Thoat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jXButton_Thoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jXButton_ThoatActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jXPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(40, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jXButton_Timkiem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17))
                    .addComponent(jXPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTabbedPane_TTTimkiem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jXPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46)
                .addComponent(jTabbedPane_TTTimkiem, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jXButton_Timkiem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXButton_Thoat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addComponent(jXPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jXDatePicker_NgayThue_TungayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXDatePicker_NgayThue_TungayActionPerformed

        try{
            if(jXDatePicker_NgayThue_Tungay.getDate().compareTo(datemin) < 0){
                JOptionPane.showMessageDialog(null, "Ngày nhỏ nhất trong quy định là 1/1/1990"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ngaythue_tungay = sdf.format(jXDatePicker_NgayThue_Tungay.getDate());
        }catch(Exception e){

        }
    }//GEN-LAST:event_jXDatePicker_NgayThue_TungayActionPerformed

    private void jXDatePicker_Ngaythue_DenngayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXDatePicker_Ngaythue_DenngayActionPerformed
        try{
            if(jXDatePicker_NgayThue_Tungay.getDate().compareTo(datemax) > 0){
                JOptionPane.showMessageDialog(null, "Ngày lớn nhất trong quy định là 1/1/2100"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ngaythue_denngay = sdf.format(jXDatePicker_Ngaythue_Denngay.getDate());
        }catch(Exception e){

        }
    }//GEN-LAST:event_jXDatePicker_Ngaythue_DenngayActionPerformed

    private void jXDatePicker_Ngaytra_TungayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXDatePicker_Ngaytra_TungayActionPerformed
        try{
            if(jXDatePicker_Ngaytra_Tungay.getDate().compareTo(datemin) < 0){
                JOptionPane.showMessageDialog(null, "Ngày nhỏ nhất trong quy định là 1/1/1990"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ngaytra_tungay = sdf.format(jXDatePicker_Ngaytra_Tungay.getDate());
        }catch(Exception e){

        }
    }//GEN-LAST:event_jXDatePicker_Ngaytra_TungayActionPerformed

    private void jXDatePicker_Ngaytra_DenngayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXDatePicker_Ngaytra_DenngayActionPerformed
        try{
            if(jXDatePicker_Ngaytra_Tungay.getDate().compareTo(datemax) > 0){
                JOptionPane.showMessageDialog(null, "Ngày lớn nhất trong quy định là 1/1/2100"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
                return;
            }
            ngaytra_denngay = sdf.format(jXDatePicker_Ngaytra_Denngay.getDate());
        }catch(Exception e){

        }
    }//GEN-LAST:event_jXDatePicker_Ngaytra_DenngayActionPerformed

    private void jTabbedPane_TTTimkiemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane_TTTimkiemMouseClicked
        if(jTabbedPane_TTTimkiem.getSelectedIndex() == 0){
            dieukien_timkiem = dk_phong;
        }
        else if(jTabbedPane_TTTimkiem.getSelectedIndex() == 1){
            dieukien_timkiem = dk_ngaythue;
        }
        else if(jTabbedPane_TTTimkiem.getSelectedIndex() == 2){
            dieukien_timkiem = dk_ngaytra;
        }
    }//GEN-LAST:event_jTabbedPane_TTTimkiemMouseClicked

    private void jXButton_TimkiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_TimkiemActionPerformed

        if(dieukien_timkiem == dk_phong){
            try{
                TimKiemPhong();
                clear();
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, "Không tim thấy"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
            }
        }
        else if(dieukien_timkiem == dk_ngaythue){
            SimpleDateFormat datefor = new SimpleDateFormat();
            datefor.setLenient(false);
            datefor.applyPattern("dd/MM/yyyy");

            if(ngaythue_tungay.equals("") || ngaythue_denngay.equals("")){
                JOptionPane.showMessageDialog(null, "Vui lòng chọn 'Từ ngày' và 'Đến ngày'"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
            }

            try{
                TimKiemNgayThue();
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, "Vui lòng chọn 'Từ ngày' và 'Đến ngày'"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
            }
        }else if(dieukien_timkiem == dk_ngaytra){

            if(ngaytra_tungay.equals("") || ngaytra_denngay.equals("")){
                JOptionPane.showMessageDialog(null, "Vui lòng chọn 'Từ ngày' và 'Đến ngày'"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
            }

            try{
                TimKiemNgayTra();
            }catch(Exception e){
                JOptionPane.showMessageDialog(null, "Vui lòng chọn 'Từ ngày' và 'Đến ngày'"
                    , "Warning", JOptionPane.WARNING_MESSAGE);
            }
        }
    }//GEN-LAST:event_jXButton_TimkiemActionPerformed

    private void jXButton_ThoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jXButton_ThoatActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jXButton_ThoatActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox_Tenloaiphong;
    private javax.swing.JComboBox jComboBox_Tenphong;
    private javax.swing.JComboBox jComboBox_Tinhtrang;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane_TTTimkiem;
    private org.jdesktop.swingx.JXButton jXButton_Thoat;
    private org.jdesktop.swingx.JXButton jXButton_Timkiem;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_NgayThue_Tungay;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_Ngaythue_Denngay;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_Ngaytra_Denngay;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker_Ngaytra_Tungay;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel2;
    private org.jdesktop.swingx.JXLabel jXLabel3;
    private org.jdesktop.swingx.JXLabel jXLabel4;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private org.jdesktop.swingx.JXLabel jXLabel6;
    private org.jdesktop.swingx.JXLabel jXLabel7;
    private org.jdesktop.swingx.JXLabel jXLabel8;
    private org.jdesktop.swingx.JXLabel jXLabel9;
    private org.jdesktop.swingx.JXLabel jXLabel_Tinhtrang;
    private org.jdesktop.swingx.JXPanel jXPanel1;
    private org.jdesktop.swingx.JXPanel jXPanel2;
    private org.jdesktop.swingx.JXPanel jXPanel3;
    private org.jdesktop.swingx.JXPanel jXPanel5;
    private org.jdesktop.swingx.JXPanel jXPanel6;
    private org.jdesktop.swingx.JXTable jXTable_Danhsachphong;
    // End of variables declaration//GEN-END:variables
}
